package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 注册相关
 * Created by MartinKent on 2016/10/27.
 */

public class SignUpService extends BasicService<JSONArray> {

    private static Object checkNull(Object object) {
        return object == null ? "" : object;
    }
//注册用户
    public void signUp(
            long companyId, boolean autoPassword, String password1, String password2,
            boolean autoScreenName, String screenName, String emailAddress,
            long facebookId, String openId, String locale, String firstName, String middleName, String lastName,
            long prefixId, long suffixId, boolean male, int birthdayMonth, int birthdayDay, int birthdayYear, String jobTitle,
            String groupIds, String organizationIds, String roleIds, String userGroupIds, String addresses,
            String emailAddresses, String phones, String websites, String announcementsDelivers,
            boolean sendEmail, final Callback<SignUpResult> callback) {
//                            companyId: 20155,
//                            autoPassword: false,
//                            password1: 'lm12345',
//                            password2: 'lm12345',
//                            autoScreenName: false,
//                            screenName: 'test123',
//                            emailAddress: 'xiaolong.jiang@linemoney.com',
//                            facebookId: 0,
//                            openId: '',
//                            locale: zh_CN,
//                            firstName: 'Test123',
//                            middleName: '',
//                            lastName: 'Test123',
//                            prefixId: 1,
//                            suffixId: 1,
//                            male: true,
//                            birthdayMonth: 0,
//                            birthdayDay: 1,
//                            birthdayYear: 1970,
//                            jobTitle: 'Regular User-普通用户',
//                            groupIds: null,
//                            organizationIds: null,
        try {
            JSONObject _result = new JSONObject();
            _result.put("companyId", companyId);
            _result.put("autoPassword", autoPassword);
            _result.put("password1", checkNull(password1));
            _result.put("password2", checkNull(password2));
            _result.put("autoScreenName", autoScreenName);
            _result.put("screenName", checkNull(screenName));
            _result.put("emailAddress", checkNull(emailAddress));
            _result.put("facebookId", facebookId);
            _result.put("openId", checkNull(openId));
            _result.put("locale", checkNull(locale));
            _result.put("firstName", checkNull(firstName));
            _result.put("middleName", checkNull(middleName));
            _result.put("lastName", checkNull(lastName));
            _result.put("prefixId", prefixId);
            _result.put("suffixId", suffixId);
            _result.put("male", male);
            _result.put("birthdayMonth", birthdayMonth);
            _result.put("birthdayDay", birthdayDay);
            _result.put("birthdayYear", birthdayYear);
            _result.put("jobTitle", checkNull(jobTitle));
            _result.put("groupIds", checkNull(groupIds));
            _result.put("organizationIds", checkNull(organizationIds));
            _result.put("roleIds", checkNull(roleIds));
            _result.put("userGroupIds", checkNull(userGroupIds));
            _result.put("addresses", checkNull(addresses));
            _result.put("emailAddresses", checkNull(emailAddresses));
            _result.put("phones", checkNull(phones));
            _result.put("websites", checkNull(websites));
            _result.put("announcementsDelivers", checkNull(announcementsDelivers));
            _result.put("sendEmail", sendEmail);

            String api = "/user/add-user";
            invoke(0, api, _result, new Callback<JSONArray>() {
                @Override
                public void onSuccess(int what, JSONArray result) {
                    if (null != callback) {
                        try {
                            callback.onSuccess(what, DPGsonUtil.fromJson(result.get(0).toString(), SignUpResult.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                            callback.onError(what, 0, e.getMessage(), e);
                        }
                    }
                }

                @Override
                public void onError(int what, int type, String msg, Exception e) {
                    if (null != callback) {
                        callback.onError(what, 0, e.getMessage(), e);
                    }
                }
            }, false);
        } catch (JSONException e) {
            e.printStackTrace();
            if (null != callback) {
                callback.onError(0, 0, e.getMessage(), e);
            }
        }
    }

    public static class SignUpResult {
        private boolean agreedToTermsOfUse;

        private String comments;

        private String companyId;

        private String contactId;

        private String createDate;

        private boolean defaultUser;

        private String emailAddress;

        private boolean emailAddressVerified;

        private String facebookId;

        private String failedLoginAttempts;

        private String firstName;

        private String graceLoginCount;

        private String greeting;

        private String jobTitle;

        private String languageId;

        private String lastFailedLoginDate;

        private String lastLoginDate;

        private String lastLoginIP;

        private String lastName;

        private String ldapServerId;

        private boolean lockout;

        private String lockoutDate;

        private String loginDate;

        private String loginIP;

        private String middleName;

        private String modifiedDate;

        private String openId;

        private int portraitId;

        private String reminderQueryAnswer;

        private String reminderQueryQuestion;

        private String screenName;

        private String status;

        private String timeZoneId;

        private String userId;

        private String uuid;

        public void setAgreedToTermsOfUse(boolean agreedToTermsOfUse) {
            this.agreedToTermsOfUse = agreedToTermsOfUse;
        }

        public boolean getAgreedToTermsOfUse() {
            return this.agreedToTermsOfUse;
        }

        public void setComments(String comments) {
            this.comments = comments;
        }

        public String getComments() {
            return this.comments;
        }

        public void setCompanyId(String companyId) {
            this.companyId = companyId;
        }

        public String getCompanyId() {
            return this.companyId;
        }

        public void setContactId(String contactId) {
            this.contactId = contactId;
        }

        public String getContactId() {
            return this.contactId;
        }

        public void setCreateDate(String createDate) {
            this.createDate = createDate;
        }

        public String getCreateDate() {
            return this.createDate;
        }

        public void setDefaultUser(boolean defaultUser) {
            this.defaultUser = defaultUser;
        }

        public boolean getDefaultUser() {
            return this.defaultUser;
        }

        public void setEmailAddress(String emailAddress) {
            this.emailAddress = emailAddress;
        }

        public String getEmailAddress() {
            return this.emailAddress;
        }

        public void setEmailAddressVerified(boolean emailAddressVerified) {
            this.emailAddressVerified = emailAddressVerified;
        }

        public boolean getEmailAddressVerified() {
            return this.emailAddressVerified;
        }

        public void setFacebookId(String facebookId) {
            this.facebookId = facebookId;
        }

        public String getFacebookId() {
            return this.facebookId;
        }

        public void setFailedLoginAttempts(String failedLoginAttempts) {
            this.failedLoginAttempts = failedLoginAttempts;
        }

        public String getFailedLoginAttempts() {
            return this.failedLoginAttempts;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getFirstName() {
            return this.firstName;
        }

        public void setGraceLoginCount(String graceLoginCount) {
            this.graceLoginCount = graceLoginCount;
        }

        public String getGraceLoginCount() {
            return this.graceLoginCount;
        }

        public void setGreeting(String greeting) {
            this.greeting = greeting;
        }

        public String getGreeting() {
            return this.greeting;
        }

        public void setJobTitle(String jobTitle) {
            this.jobTitle = jobTitle;
        }

        public String getJobTitle() {
            return this.jobTitle;
        }

        public void setLanguageId(String languageId) {
            this.languageId = languageId;
        }

        public String getLanguageId() {
            return this.languageId;
        }

        public void setLastFailedLoginDate(String lastFailedLoginDate) {
            this.lastFailedLoginDate = lastFailedLoginDate;
        }

        public String getLastFailedLoginDate() {
            return this.lastFailedLoginDate;
        }

        public void setLastLoginDate(String lastLoginDate) {
            this.lastLoginDate = lastLoginDate;
        }

        public String getLastLoginDate() {
            return this.lastLoginDate;
        }

        public void setLastLoginIP(String lastLoginIP) {
            this.lastLoginIP = lastLoginIP;
        }

        public String getLastLoginIP() {
            return this.lastLoginIP;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public String getLastName() {
            return this.lastName;
        }

        public void setLdapServerId(String ldapServerId) {
            this.ldapServerId = ldapServerId;
        }

        public String getLdapServerId() {
            return this.ldapServerId;
        }

        public void setLockout(boolean lockout) {
            this.lockout = lockout;
        }

        public boolean getLockout() {
            return this.lockout;
        }

        public void setLockoutDate(String lockoutDate) {
            this.lockoutDate = lockoutDate;
        }

        public String getLockoutDate() {
            return this.lockoutDate;
        }

        public void setLoginDate(String loginDate) {
            this.loginDate = loginDate;
        }

        public String getLoginDate() {
            return this.loginDate;
        }

        public void setLoginIP(String loginIP) {
            this.loginIP = loginIP;
        }

        public String getLoginIP() {
            return this.loginIP;
        }

        public void setMiddleName(String middleName) {
            this.middleName = middleName;
        }

        public String getMiddleName() {
            return this.middleName;
        }

        public void setModifiedDate(String modifiedDate) {
            this.modifiedDate = modifiedDate;
        }

        public String getModifiedDate() {
            return this.modifiedDate;
        }

        public void setOpenId(String openId) {
            this.openId = openId;
        }

        public String getOpenId() {
            return this.openId;
        }

        public void setPortraitId(int portraitId) {
            this.portraitId = portraitId;
        }

        public int getPortraitId() {
            return this.portraitId;
        }

        public void setReminderQueryAnswer(String reminderQueryAnswer) {
            this.reminderQueryAnswer = reminderQueryAnswer;
        }

        public String getReminderQueryAnswer() {
            return this.reminderQueryAnswer;
        }

        public void setReminderQueryQuestion(String reminderQueryQuestion) {
            this.reminderQueryQuestion = reminderQueryQuestion;
        }

        public String getReminderQueryQuestion() {
            return this.reminderQueryQuestion;
        }

        public void setScreenName(String screenName) {
            this.screenName = screenName;
        }

        public String getScreenName() {
            return this.screenName;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getStatus() {
            return this.status;
        }

        public void setTimeZoneId(String timeZoneId) {
            this.timeZoneId = timeZoneId;
        }

        public String getTimeZoneId() {
            return this.timeZoneId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUserId() {
            return this.userId;
        }

        public void setUuid(String uuid) {
            this.uuid = uuid;
        }

        public String getUuid() {
            return this.uuid;
        }
    }
}
